package com.ed.utils;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;

public class TimeUtil {
    /**
     * 获取昨日零点的时间
     * @return
     */
    public static LocalDateTime getYesterdayStart() {
        // 获取当前日期并减去1天得到昨日日期
        LocalDate yesterday = LocalDate.now().minusDays(1);
        // 将昨日日期转换为当天的起始时间（00:00:00）
        return yesterday.atStartOfDay();
    }

    /**
     * 获取今日零点的时间
     * @return
     */
    public static LocalDateTime getTodayStart() {
        LocalDate now = LocalDate.now();
        return now.atStartOfDay();
    }

    /**
     * 计算两个时间点之间的差异，单位为分钟
     * @param startTime
     * @param endTime
     * @return
     */
    public static Double getTimeDifference(LocalDateTime startTime, LocalDateTime endTime) {
        // 计算两个时间点之间的差异
        Duration duration = Duration.between(startTime, endTime);

        // 获取相差的总秒数
        long totalSecondsBetween = duration.getSeconds();

        // 将总秒数转换为分钟数，并保留小数部分
        double minutesBetween = totalSecondsBetween / 60.0;

        return minutesBetween;
    }
}
